<template>
  <div>
    <el-dialog :title="info.isAdd ? '添加' : '编辑'" :visible.sync="info.isShow" @close="close">
      <div>{{ user }}</div>
      <el-form :model="user" label-width="80px">
         <el-form-item label="手机号">
          <el-input v-model="user.phone" clearable></el-input>
        </el-form-item>
        <el-form-item label="昵称">
          <el-input v-model="user.nickname" clearable></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input type="password" placeholder="留空则不修改" clearable show-password v-model="user.password"></el-input>
        </el-form-item>
        <el-form-item label="状态">
          <el-switch
            v-model="user.status"
            :active-value="1"
            :inactive-value="2"
          ></el-switch>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="update">修 改</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import path from 'path'
import { mapGetters, mapActions } from "vuex";
import { reqmemberinfo,reqmemberedit } from "../../../http/api";
import { successAlert,errorAlert } from "../../../utils/alert";
import { formClose } from "../../../mixins/index";
export default {
  mixins: [formClose],
  props: ["info"],
  data() {
    return {
      user: {
        nickname: '',
        phone: "",
        password: '',
        status: 1,
      },
    };
  },
  computed: {
    ...mapGetters({}),
  },
  mounted() {},
  methods: {
    ...mapActions({getList:'member/getList'}),
    //清空表单
    empty() {
      this.user={
        nickname: '',
        phone: "",
        password: '',
        status: 1,
      }
    },
    //获取一条用户信息
    async getOne(id) {
      let { data: res } = await  reqmemberinfo({ uid:id });
      console.log(res);
      if (res.code == 200) {
        this.user = res.list;
        this.user.password = '';
      }
    },
    //修改
    async update() {
      console.log(this.user);
      let { data: res } = await reqmemberedit(this.user);
      if (res.code == 200) {
        successAlert(res.msg);
        //添加成功关闭弹窗
        this.info.isShow = false;
        //清空数据
        this.empty();
        //重新请求列表页数据
        this.getList();
      }
    },
  },
};
</script>
<style scoped lang="less">
@import "../../../less/index.less";
</style>